package com.itheima.job;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;

public class XMLTest02 {
    public static void main(String[] args) throws DocumentException {
        SAXReader saxReader = new SAXReader();
        Document document = saxReader.read(new File("day17\\xml\\books.xml"));
        Element rootElement = document.getRootElement();
        List<Element> list = rootElement.elements();
        for (Element element : list) {
            Attribute id = element.attribute("id");
            Attribute cbs = element.attribute("出版社");
            System.out.println("id:"+id.getValue()+" 出版社："+cbs.getValue());
            String name = element.element("name").getText();
            String author = element.element("author").getText();
            String price = element.element("price").getText();
            String body = element.element("body").getText();
            System.out.println("书名："+name+" 作者："+author+" 价格："+price+" "+body);
        }
    }
}
